package models;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import com.feth.play.module.pa.user.AuthUser;

import play.db.ebean.Model;

@Entity
@Table(name = "tags")
public class Tag extends Model {
	
	private static final long serialVersionUID = 1L;
	
	@Column(name = "id")
	@GeneratedValue(generator = "SEQ_TABLE", strategy = GenerationType.TABLE)
	@Id
	@TableGenerator(name = "SEQ_TABLE")
	private long id;

	@Column(name = "project")
	@ManyToOne(fetch = FetchType.LAZY)
	private Project project;
	
	@Column(name = "tag")
	private String tag;

	public static final Finder<Long, Tag> find = new Finder<Long, Tag>(long.class, Tag.class);

	public long getId() {
		return id;
	}

	public void update(final AuthUser authUser) {
		
	}

	
	public Project getProject()
	{
		return project;
	}

	public void setProject(Project project)
	{
		this.project = project;
	}

	public String getTag()
	{
		return tag;
	}

	public void setTag(String tag)
	{
		this.tag = tag;
	}

	public static Tag create(final AuthUser authUser) {
		final Tag account = new Tag();
		account.update(authUser);
		return account;
	}

	public static Tag create(final Tag tag) {
		final Tag newTag = new Tag();
		newTag.setProject(tag.getProject());
		newTag.setTag(tag.getTag());
		return newTag;
	}

	public static Tag findByProviderKey(final Project project, final String tag) {
		return find.where().eq("project", project).eq("tag", tag).findUnique();
	}
}
